<!-- 进入通道 -->
<template>
  <div class="acenter all">
    <div class="row height80 mb40 acenter channel">
      <text class="font28 text1 mr20">{{ T('上限') }}</text>
      <VPriceInputItem :dPrice="dPrice" ref="input1" min="0" max="100000000000" class="all" key="price1"
        @onPriceChange="onPriceChange1" />
    </div>
    <div class="row height80 acenter channel">
      <text class="font28 text1 mr20">{{ T('下限') }}</text>
      <VPriceInputItem :dPrice="0" ref="input2" min="0" max="100000000000" class="all" key="price2"
        @onPriceChange="onPriceChange2" />
    </div>
  </div>
</template>

<script>
  import VPriceInputItem from "@/aide/view/VPriceInputItem.vue";
  import jmodal from "@/_js/modal";
  import jconfig from "@/_js/config";
  import I18N from "@/_i18n/i18n";
  var T = I18N.t;
  export default {
    components: {
      VPriceInputItem,
    },

    props: {
      //条件
      condition: {
        type: Object,
        default: function () {
          return {};
        },
      },
      //当前价格
      dPrice: {
        type: String,
        default: "",
        dLength: 0,
      },
    },

    data() {
      return {
        Config: jconfig,
        T: T,
      };
    },

    mounted() {
      this.dLength = this.getDecimalPlaces(this.dPrice);
      if (this.condition.value1 && this.condition.value1 != "") {
        let price1 = this.condition.value1;
        this.$refs.input1.price = price1;
      } else {
        this.$refs.input1.price = this.dPrice;
      }
      if (this.condition.value2 && this.condition.value2 != "") {
        let price2 = this.condition.value2;
        this.$refs.input2.price = price2;
      } else {
        this.$refs.input2.price = 0;
      }
      this.onPriceChange1(this.$refs.input1.price);
      this.onPriceChange2(this.$refs.input2.price);
    },

    computed: {},

    methods: {
      onPriceChange1(e) {
        let price = Number(e);
        let nPrice = price.toFixed(this.dLength);
        this.$emit("onPriceChangeValue1", nPrice);
      },
      onPriceChange2(e) {
        let price = Number(e);
        let nPrice = price.toFixed(this.dLength);
        this.$emit("onPriceChangeValue2", nPrice);
      },
      getDecimalPlaces(value) {
        if (!value.includes(".")) return 0; // 如果没有小数点，返回 0
        return value.split(".")[1].length; // 返回小数点后的位数
      },
      blur() {
        this.$refs.input1 && this.$refs.input1.blur();
        this.$refs.input2 && this.$refs.input2.blur();
      },
    },
  };
</script>

<style src="@/_css/style.css" ></style>
<style scoped>
  .channel {
    width: 690px;
  }
</style>
